home *** CD-ROM | disk | FTP | other *** search
- $$Message Main, mm:mmMain$Prototype.name$.c
- $$File mm:mmMain$Prototype.name$.c
- /* mmMain$Prototype.name$ */
-
- /*
- Program name: mmMain$Prototype.name$
- Function: This is the main module for this program.
- History: $Date$ Original by $Author$
-
- */
-
- #include "mmCommon$Prototype.name$.h" /* Common */
- #include "Common$Prototype.name$.h" /* Common */
-
- #include "InitExit$Prototype.name$.h" /* Init, Exit handlers */
- #include "events$Prototype.name$.h" /* Extra event handlers */
-
- $$Loop Windows
- #include "$Worksheet.name$.h" /* Window, $Worksheet.FullName$ */
- $$EndLoop
- #include "mmMenu$Prototype.name$.h" /* Menus */
-
-
- Boolean DoIt; /* Flag saying an event is ready */
- short code; /* Determine event type */
- WindowPtr whichWindow; /* See which window for event */
- long mResult; /* Menu list and item selected values */
- short theMenu,theItem; /* Menu list and item selected */
- Boolean Is_A_Dialog; /* Flag for modless dialogs */
- short charCode, itemHit; /* For modeless dialogs*/
- char ch; /* Key pressed in Ascii */
- Boolean DoTheModelessEvent, CmdDown; /* For modeless dialogs*/
- WindowPeek thePeeked; /* For modeless dialogs*/
-
- /* Handle key strokes */
- static void DoKeyEvent(void);
-
- /* Handle a diskette inserted */
- static void DoDiskEvent(void);
-
- $$if HasZoomWindow
- /* Handle a window zoom */
- static void DoZoom(WindowPtr whichWindow, short code);
-
- $$endif
- $$if HasResizableWindows
- /* Handle a window being resized */
- static void DoGrow(WindowPtr whichWindow);
-
- $$endif
- /* Handle a window being dragged */
- static void DoDrag(WindowPtr whichWindow);
-
- $$if HasGoAwayBoxes
- /* Handle a window goaway box */
- static void DoGoAway(WindowPtr whichWindow);
-
- $$endif
- /* Handle an update to the window */
- static void DoUpdate(void);
-
- /* Handle the HighLevel event */
- static void DoHighLevelEvent(void);
-
- /* MAIN entry point */
- void main(void);
-
-
- /* ======================================================= */
-
- /* Routine: WNEIsImplemented */
- /* Purpose: See if the MultiFinder trap, WaitNextEvent, is available */
-
- Boolean IsWNEIsImplemented(void) /* See if WaitNextEvent is available */
- {
- #define WNETrapNumber 0xA860 /* The expected trap number */
- #define kGestaltTrapID 0xA1AD /* The expected trap number */
-
- SysEnvRec theWorld; /* Environment record */
- OSErr discardError; /* Error code returned */
- Boolean theWNEIsImplemented; /* Value to return */
- long result; /* Value returned */
-
-
- Black_ForeColor.red = 0x0000; Black_ForeColor.green = 0x0000; Black_ForeColor.blue = 0x0000; /* Get black color */
- White_BackColor.red = 0xFFFF; White_BackColor.green = 0xFFFF; White_BackColor.blue = 0xFFFF; /* Get white color */
-
- Has.ColorQD = FALSE; /* Init to no color QuickDraw */
- Has.FPU = FALSE; /* Init to no floating point chip */
- Has.AppleEvents = FALSE; /* Whether AppleEvents are available */
- Has.AliasMgr = FALSE; /* Whether AliasMgr is available */
- Has.EditionMgr = FALSE; /* Whether EditionMgr is available */
- Has.Gestalt = FALSE; /* Whether Gestalt is available */
- Has.NewStdFile = FALSE; /* Whether NewStdFile is available */
- Has.PPCToolbox = FALSE; /* Whether PPCToolbox is available */
- Has.QuickDraw32Bit = FALSE; /* Whether 32Bit QuickDraw is available */
- InTheForeground = TRUE; /* Init to a foreground app */
-
- discardError = SysEnvirons(1, &theWorld); /* Check how old this system is */
- if (theWorld.machineType < 0) /* Negative means really old */
- {
- theWNEIsImplemented = FALSE; /* Really old ROMs, no WNE possible */
- }
- else
- {
- theWNEIsImplemented = true;
- Has.ColorQD = theWorld.hasColorQD; /* Flag for Color QuickDraw being available */
- Has.FPU = theWorld.hasFPU; /* Flag for Floating Point Math Chip being available */
- Has.Gestalt = true;
- if (Has.Gestalt) /* Do if Gestalt is available */
- {
- discardError = Gestalt(gestaltAliasMgrAttr,&result);
- if ((discardError == 0) && ((result & (0x00000001 << gestaltAliasMgrPresent)) != 0))
- Has.AliasMgr = TRUE;
-
- discardError = Gestalt(gestaltEditionMgrAttr,&result);
- if ((discardError == 0) && ((result & (0x00000001 << gestaltEditionMgrPresent)) != 0))
- Has.EditionMgr = TRUE;
-
- discardError = Gestalt(gestaltAppleEventsAttr,&result);
- if ((discardError == 0) && ((result & (0x00000001 << gestaltAppleEventsPresent)) != 0))
- Has.AppleEvents = TRUE;
-
- discardError = Gestalt(gestaltPPCToolboxAttr,&result);
- if ((discardError == 0) && ((result & (0x00000001 << gestaltPPCToolboxPresent)) != 0))
- Has.PPCToolbox = TRUE;
-
- discardError = Gestalt(gestaltQuickdrawVersion,&result);
- if ((discardError == 0) && ((result & gestalt32BitQD) != 0))
- Has.QuickDraw32Bit = TRUE;
-
- discardError = Gestalt(gestaltStandardFileAttr,&result);
- if ((discardError == 0) && ((result & (0x00000001 << gestaltStandardFile58)) != 0))
- Has.NewStdFile = TRUE;
- }
- }
-
- return(theWNEIsImplemented);
- }
-
- /* ======================================================= */
-
- /* Routine: Handle_User_Event */
- /* Purpose: Check for user events */
-
- void Handle_User_Event(void) /* Check for user events */
- {
- UserEventRec TheUserEvent; /* The user event */
-
-
- GetUserEvent(&TheUserEvent); /* Check for any user events */
- if (TheUserEvent.ID != UserEvent_None) /* Only do if we have any */
- {
-
- switch (TheUserEvent.ID) /* Key off the Event ID */
- {
- case UserEvent_Open_Window: /* Open a Window or Modeless dialog */
- switch (TheUserEvent.ID2) /* Do the appropiate window */
- {
- $$Loop Alerts
- case ResA_$Worksheet.name$:
- PA_$Worksheet.name$(); /* Open this alert */
- break;
- $$EndLoop
- $$Loop ModalDialogs
- case ResD_$Worksheet.name$:
- MPD_$Worksheet.name$(); /* Open this modal dialog */
- break;
- $$EndLoop
- $$Loop ModelessDialogs
- case ResD_$Worksheet.name$:
- Open_$Worksheet.name$(); /* Open this modeless dialog */
- break;
- $$EndLoop
- $$Loop Windows
- case ResW_$Worksheet.name$:
- Open_$Worksheet.name$(); /* Open this window */
- break;
- $$EndLoop
- default: /* Handle others */
- break;
- } /* End of the switch */
- break;
-
- case UserEvent_Close_Window: /* Close a Window or Modeless dialog */
- switch (TheUserEvent.ID2) { /* Do the appropiate window */
- $$Loop ModelessDialogs
- case ResD_$Worksheet.name$:
- Close_$Worksheet.name$(Rec_$Worksheet.name$.theDialog);/* Close this modeless dialog */
- break;
- $$EndLoop
- $$Loop Windows
- case ResW_$Worksheet.name$:
- Close_$Worksheet.name$((WindowPtr)-1); /* Close this window */
- break;
- $$EndLoop
- default: /* Handle others */
- break;
- } /* End of the switch */
- break;
-
- default: /* Not standard, must be program specific */
- Handle_UserEvent(&TheUserEvent); /* Let program specific handle it */
- break;
- } /* End of switch */
- }
- }
-
- /* ======================================================= */
-
- /* Routine: DoKeyEvent */
- /* Purpose: Handle a key pressed */
-
- static void DoKeyEvent(void) /* Handle key presses */
- {
- short charCode; /* Key code */
- char ch; /* Key pressed in Ascii */
- long mResult; /* Menu list and item, if a command key */
- short theMenu,theItem; /* Menu list and item, if command key */
-
-
- if (HandleKey(&myEvent)) /* Allow for special key handling */
- {
- charCode = myEvent.message & charCodeMask; /* Get the character */
- ch = (char)charCode; /* Change it to ASCII */
-
- if ((myEvent.modifiers & cmdKey) != 0) /* See if Command key is down */
- {
- U_EnableMenus(); /* Let us in to enable and disable menus*/
- mResult = MenuKey(ch); /* See if a menu selection */
- theMenu = HiWord(mResult); /* Get the menu list number */
- theItem = LoWord(mResult); /* Get the menu item number */
- if (theMenu != 0) /* See if a list was selected */
- Handle_My_Menu(theMenu, theItem); /* Do the menu selection */
-
- if (((ch == 'x') || (ch == 'X')) && (theInput != NIL))
- TECut(theInput); /* Handle a Cut in a TE area */
- if (((ch == 'c') || (ch == 'C')) && (theInput != NIL))
- TECopy(theInput); /* Handle a Copy in a TE area */
- if (((ch == 'v') || (ch == 'V')) && (theInput != NIL))
- TEPaste(theInput); /* Handle a Paste in a TE area */
- }
- else if (theInput != NIL)
- TEKey(ch,theInput); /* Place the normal key stroke */
- }
- }
-
- /* ======================================================= */
-
- /* Routine: DoDiskEvent */
- /* Purpose: Handle a diskette inserted */
-
- static void DoDiskEvent(void) /* Handle disk inserted */
- {
- short theError; /* Error returned from mount */
-
-
- if (HandleDisk(&myEvent)) /* Allow for special disk inserted handling */
- {
- if (HiWord(myEvent.message) != noErr) /* See if a diskette mount error */
- {
- myEvent.where.h = ((screenRect.bounds.right - screenRect.bounds.left) / 2) - (304 / 2);/* Center horz */
- myEvent.where.v = ((screenRect.bounds.bottom - screenRect.bounds.top) / 3) - (104 / 2);/* Top 3ed vertically */
- InitCursor(); /* Make sure it has an arrow cursor */
- theError = DIBadMount(myEvent.where, myEvent.message);/* Let the OS handle the diskette */
- }
- }
- }
-
- $$if HasZoomWindow
- /* ======================================================= */
-
- /* Routine: DoZoom */
- /* Purpose: Handle a window zoom */
-
- static void DoZoom(WindowPtr whichWindow, short code)/* Handle a window zoom */
- {
- Rect OldRect; /* Window rect before the zoom */
- Point myPt; /* Point for tracking zoom box */
- long theRefCon; /* Refcon with layer masked off */
-
-
- if (!Doing_MovableModal) /* Select proper window */
- {
- if (whichWindow != NIL) /* See if we have a legal window */
- {
- SetPort(whichWindow); /* Get ready to draw in this window */
-
- myPt = myEvent.where; /* Get mouse position */
- GlobalToLocal(&myPt); /* Make it relative */
-
- OldRect = whichWindow->portRect; /* Save the rect before resizing */
-
- if (TrackBox(whichWindow, myPt, code)) /* Zoom it */
- {
- ZoomWindow(whichWindow, code, TRUE); /* Resize to result */
- EraseRect(&whichWindow->portRect); /* Make sure we update the whole window effectively */
- InvalRect(&whichWindow->portRect); /* Tell ourselves to update, redraw, the window contents */
- theRefCon = GetWRefCon(whichWindow); /* Get the refcon */
- theRefCon = theRefCon & 0x00FFFFFF; /* Mask the layer out */
-
- switch (theRefCon) /* Do the appropiate window */
- {
- $$Loop Windows
- $$if Window.Zoomable
- case ResW_$Worksheet.name$:
- Resized_$Worksheet.name$(&OldRect, whichWindow);/* Resized this window */
- break;
- $$endif
- $$EndLoop
-
- default: /* Handle others */
- U_DoZoom(&OldRect, whichWindow);/* Allow user to handle others */
- break;
- }
- Mk_HiliteWindow(whichWindow); /* Hilite it again */
- }
- }
- }
- }
-
- $$endif
- $$if HasResizableWindows
- /* ======================================================= */
-
- /* Routine: DoGrow */
- /* Purpose: Handle a window resize */
-
- static void DoGrow(WindowPtr whichWindow)
- {
- Rect OldRect; /* Window rect before the grow */
- Point myPt; /* Point for tracking grow box */
- Rect GrowRect; /* Set the grow bounds */
- long mResult; /* Result from the grow */
- long theRefCon; /* Refcon with layer masked off */
-
-
- if (!Doing_MovableModal) /* Select proper window */
- {
- if (whichWindow != nil) /* See if we have a legal window */
- {
- SetPort(whichWindow); /* Get ready to draw in this window */
-
- myPt = myEvent.where; /* Get mouse position */
- GlobalToLocal(&myPt); /* Make it relative */
-
- OldRect = whichWindow->portRect; /* Save the rect before resizing */
-
- SetRect(&GrowRect, 4, 4, (screenRect.bounds.right - screenRect.bounds.left)-4,
- (screenRect.bounds.bottom - screenRect.bounds.top) - 4);/* l,t,r,b */
- mResult = GrowWindow(whichWindow, myEvent.where, &GrowRect);/* Grow it */
- SizeWindow(whichWindow, LoWord(mResult), HiWord(mResult), true);/* Resize to result */
-
- theRefCon = GetWRefCon(whichWindow); /* Get the refcon */
- theRefCon = theRefCon & 0x00FFFFFF; /* Mask the layer out */
-
- switch (theRefCon) /* Do the appropiate window */
- {
- $$Loop Windows
- $$if Window.Resizable
- case ResW_$Worksheet.name$:
- Resized_$Worksheet.name$(&OldRect, whichWindow);/* Resized this window */
- break;
- $$endif
- $$EndLoop
-
- default: /* allow other buttons, trap for debug */
- U_DoGrow(&OldRect, whichWindow); /* Allow user to handle others */
- break; /* end of otherwise */
- } /* end of switch */
-
- SetPort(whichWindow); /* Get ready to draw in this window */
-
- myPt.h = whichWindow->portRect.right - whichWindow->portRect.left;/* Local right edge */
- myPt.v = whichWindow->portRect.bottom - whichWindow->portRect.top;/* Local bottom edge */
-
- SetRect(&GrowRect, 0, OldRect.bottom - 15, OldRect.right + 15, OldRect.bottom + 15);/* Position for horz scrollbar area */
- EraseRect(&GrowRect); /* Erase old area */
- InvalRect(&GrowRect); /* Flag us to update it */
-
- SetRect(&GrowRect, OldRect.right - 15, 0, OldRect.right + 15, OldRect.bottom + 15);/* Position for vert scrollbar area */
- EraseRect(&GrowRect); /* Erase old area */
- InvalRect(&GrowRect); /* Flag us to update it */
-
- DrawGrowIcon(whichWindow); /* Draw the grow Icon again */
- }
- }
- }
-
- $$endif
- /* ======================================================= */
-
- /* Routine: DoDrag */
- /* Purpose: Drag a window around */
-
- static void DoDrag(WindowPtr whichWindow)
- {
- Rect OldRect; /* Window rect before the drag */
- Rect tempRect; /* temporary rect */
- long theRefCon; /* Refcon with layer masked off */
-
-
- if ((!Doing_MovableModal) || (Doing_MovableModal && (whichWindow == FrontWindow())))/* See if OK to drag */
- {
- OldRect = whichWindow->portRect; /* Save the rect before resizing */
-
- if (!Doing_MovableModal) /* Select proper window */
- Mk_HiliteWindow(whichWindow);
- SetRect(&tempRect, -32000, -32000, 32000, 32000);
- Mk_DragWindow(whichWindow, myEvent.where, tempRect);/* Drag the window */
-
- theRefCon = GetWRefCon(whichWindow); /* Get the refcon */
- theRefCon = theRefCon & 0x00FFFFFF; /* Mask the layer out */
- switch (theRefCon) /* Do the appropiate window */
- {
- $$Loop ModelessDialogs
- case ResD_$Worksheet.name$:
- Moved_$Worksheet.name$(&OldRect, whichWindow); /* Moved this modeless dialog */
- break;
- $$EndLoop
- $$Loop Windows
- case ResW_$Worksheet.name$:
- U_Moved$Worksheet.name$(&OldRect, whichWindow);/* Moved this window */
- break;
- $$EndLoop
-
- default: /* allow other buttons, trap for debug */
- U_Moved(&OldRect, whichWindow); /* Allow user to handle others */
- break; /* end of otherwise */
- } /* end of switch */
- }
- }
-
- $$if HasGoAwayBoxes
- /* ======================================================= */
-
- /* Routine: DoGoAway */
- /* Purpose: Close a window */
-
- static void DoGoAway(WindowPtr whichWindow)
- {
- long theRefCon; /* Refcon with layer masked off */
-
-
- if (!Doing_MovableModal) /* Select proper window */
- {
- if (TrackGoAway(whichWindow,myEvent.where)) /* See if mouse released in GoAway box */
- {
- theRefCon = GetWRefCon(whichWindow); /* Get the refcon */
- theRefCon = theRefCon & 0x00FFFFFF; /* Mask the layer out */
- switch (theRefCon) /* Do the appropiate window */
- {
- $$Loop ModelessDialogs
- $$if ModelessDialog.GoAway
- case ResD_$Worksheet.name$:
- Close_$Worksheet.name$(whichWindow); /* Close this modeless dialog */
- break;
- $$endif
- $$EndLoop
- $$Loop Windows
- $$if Window.GoAway
- case ResW_$Worksheet.name$:
- Close_$Worksheet.name$(whichWindow); /* Close this window */
- break;
- $$endif
- $$EndLoop
-
- default: /* allow other buttons, trap for debug */
- U_GoAway(whichWindow); /* Allow user to handle others */
- break; /* end of otherwise */
- } /* end of switch */
- }
- }
- }
-
- $$endif
- /* ======================================================= */
-
- /* Routine: DoInContent */
- /* Purpose: Pressed in the content area */
-
- void DoInContent(WindowPtr whichWindow,EventRecord *myEvent)
- {
- long theRefCon; /* Refcon with layer masked off */
-
-
- if (!Doing_MovableModal) /* Select proper window */
- {
- if (Mk_Is_FrontWindow(whichWindow) == false) /* See if already selected or not, in front if selected */
- Mk_HiliteWindow(whichWindow);
- else
- {
- SetPort(whichWindow); /* Get ready to draw in this window */
- Mk_HiliteWindow(whichWindow);
- theRefCon = GetWRefCon(whichWindow); /* Get the refcon */
- theRefCon = theRefCon & 0x00FFFFFF; /* Mask the layer out */
-
- switch (theRefCon) /* Do the appropiate window */
- {
- $$Loop Windows
- case ResW_$Worksheet.name$:
- Do_$Worksheet.name$(myEvent); /* Handle this window */
- break;
- $$EndLoop
-
- default: /* allow other buttons, trap for debug */
- U_InContent(myEvent,whichWindow); /* Allow user to handle others */
- break; /* end of otherwise */
- } /* end of switch */
- }
- }
- }
-
- /* ======================================================= */
-
- /* Routine: DoUpdate */
- /* Purpose: Got an update event */
-
- static void DoUpdate(void)
- {
- WindowPtr whichWindow; /* See which window for event */
- long theRefCon; /* Refcon with layer masked off */
-
-
- whichWindow = (WindowPtr)myEvent.message; /* Get the window the update is for */
-
- BeginUpdate(whichWindow); /* Set the clipping to the update area */
- theRefCon = GetWRefCon(whichWindow); /* Get the refcon */
- theRefCon = theRefCon & 0x00FFFFFF; /* Mask the layer out */
- switch (theRefCon) /* Do the appropiate window */
- {
- $$Loop Windows
- case ResW_$Worksheet.name$:
- Update_$Worksheet.name$(whichWindow); /* Update this window */
- break;
- $$EndLoop
-
- default: /* allow other buttons, trap for debug */
- U_Update(whichWindow); /* Allow user to handle others */
- break; /* end of otherwise */
- } /* end of switch */
- EndUpdate(whichWindow); /* Return to normal clipping area */
- }
-
- /* ======================================================= */
-
- /* Routine: DoActivate */
- /* Purpose: Got an activate or deactivate event */
-
- void DoActivate(void)
- {
- WindowPtr whichWindow; /* See which window for event */
- Boolean Do_An_Activate; /* Flag to pass */
- long theRefCon; /* Refcon with layer masked off */
-
-
- whichWindow = (WindowPtr)myEvent.message; /* Get the window the update is for */
-
- Do_An_Activate = ((myEvent.modifiers & 0x0001) != 0);/* Make sure it is Activate and not DeActivate */
- theRefCon = GetWRefCon(whichWindow); /* Get the refcon */
- theRefCon = theRefCon & 0x00FFFFFF; /* Mask the layer out */
- switch (theRefCon) /* Do the appropiate window */
- {
- $$Loop Windows
- case ResW_$Worksheet.name$:
- Activate_$Worksheet.name$(whichWindow,Do_An_Activate); /* Activate or deactivate this window */
- break;
- $$EndLoop
-
- default: /* allow other buttons, trap for debug */
- U_Activate(whichWindow,Do_An_Activate); /* Allow user to handle others */
- break; /* end of otherwise */
- } /* end of switch */
- }
-
- /* ======================================================= */
-
- /* Routine: DoHighLevelEvent */
- /* Purpose: Got a High Level event */
-
- static void DoHighLevelEvent(void)
- {
- OSErr err; /* Error */
-
-
- err = AEProcessAppleEvent(&myEvent); /* Go to the processor of apple events */
- }
-
- /* ======================================================= */
- /* ======================================================= */
-
- void main(void) /* Start of main body */
- {
-
- MoreMasters(); /* This reserves space for more handles */
- MaxApplZone(); /* Give us room for memory allocation */
- InitGraf(&QDPort); /* Quickdraw Init */
- InitFonts(); /* Font manager init */
- InitWindows(); /* Window manager init */
- InitMenus(); /* Menu manager init */
- TEInit(); /* Text edit init */
- InitDialogs(0L); /* Dialog manager */
-
- FlushEvents(everyEvent , 0); /* Clear out all events */
- InitCursor(); /* Make an arrow cursor */
-
- doneFlag = FALSE; /* Do not exit program yet */
-
- OpenSplashWindow();
-
- Init_My_Menus(); /* Initialize menu bar */
-
- theInput = nil; /* Init to no text edit selection active */
-
- SleepValue = 40; /* Set sleep value */
- WNE = IsWNEIsImplemented(); /* See if WaitNextEvent is available */
-
- UserEventList = nil; /* No user events yet */
-
- cursorRgn = NewRgn(); /* Cursor region for WaitNextEvent */
-
- if (Has.AppleEvents) /* See if AppleEvents are available */
- InitAppleEvents(); /* Initialize for AppleEvents */
-
- Printing.hPrint = nil; /* Init to no print record yet */
- Printing.PrinterIsOpen = false; /* We are not printing yet */
-
- U_InitPreferences(); /* Set default preferences */
-
- $$Loop Alerts
- InitA_$Worksheet.name$(); /* Initialize Alert, $Worksheet.FullName$ */
- $$EndLoop
- $$Loop ModalDialogs
- InitD_$Worksheet.name$(); /* Initialize Modal Dialog, $Worksheet.FullName$ */
- $$EndLoop
- $$Loop ModelessDialogs
- Init_$Worksheet.name$(); /* Initialize Modeless Dialog, $Worksheet.FullName$ */
- $$EndLoop
- $$Loop Windows
- Init_$Worksheet.name$(); /* Initialize Window, $Worksheet.FullName$ */
- $$EndLoop
-
- Mk_ClearLayers(); /* Init layer array */
- Doing_MovableModal = false; /* Not currently doing a movable modal */
-
- ApplInit$Prototype.name$(); /* Handle extra program initialization */
-
- GetPreferences(); /* Get preferences */
-
- $$Loop Alerts
- $$if Worksheet.OpenAtStartup
- PA_$Worksheet.name$(); /* Open at program start, $Worksheet.FullName$ */
- $$endif
- $$EndLoop
- $$Loop ModalDialogs
- $$if Worksheet.OpenAtStartup
- MPD_$Worksheet.name$(); /* Open at program start, $Worksheet.FullName$ */
- $$endif
- $$EndLoop
- $$Loop ModelessDialogs
- $$if Worksheet.OpenAtStartup
- Open_$Worksheet.name$(); /* Open at program start, $Worksheet.FullName$ */
- $$endif
- $$EndLoop
- $$Loop Windows
- $$if Worksheet.OpenAtStartup
- Open_$Worksheet.name$(); /* Open at program start, $Worksheet.FullName$ */
- $$endif
- $$EndLoop
-
- CloseSplashWindow();
-
- do
- {
- ApplLoop$Prototype.name$(); /* Hook into the main loop */
-
- Handle_User_Event(); /* Check for user events */
-
- if (theInput != NIL) /* See if a TE is active */
- TEIdle(theInput); /* Blink the cursor if everything is ok */
-
- if (WNE) /* See if do the MultiFinder way */
- DoIt = WaitNextEvent(everyEvent, &myEvent, SleepValue, cursorRgn);/* Wait for an event */
- else
- {
- SystemTask(); /* For support of desk accessories */
- DoIt = GetNextEvent(everyEvent, &myEvent); /* See if an event is ready */
- }
-
- ApplEvent$Prototype.name$(&DoIt,&myEvent); /* Let us at the event first */
-
- if (DoIt) /* If event then... */
- {
- Is_A_Dialog = IsDialogEvent(&myEvent); /* See if a modeless dialog event */
- if (Is_A_Dialog == TRUE) /* Handle a dialog event */
- {
- if (myEvent.what == updateEvt) /* Handle the update of a Modeless Dialog */
- {
- whichWindow = (WindowPtr)myEvent.message; /* Get the window the update is for */
- BeginUpdate(whichWindow); /* Set update clipping area */
- $$Loop ModelessDialogs
- Update_$Worksheet.name$(whichWindow); /* Update Modeless Dialog, $Worksheet.FullName$ */
- $$EndLoop
- EndUpdate(whichWindow); /* Return to normal clipping area */
- }
- else
- {
- DoTheModelessEvent = TRUE; /* Go ahead and do it so far */
-
- if (myEvent.what == keyDown) /* Check the key down, for a command key event */
- {
- CmdDown = ((myEvent.modifiers / cmdKey) & 1);/* Get the command key state */
- charCode = myEvent.message & charCodeMask;/* Get the character */
- ch = (char)charCode; /* Change it to ASCII */
-
- if ((charCode == 13) || (charCode == 0x03))/* CR or Enter */
- DoTheModelessEvent = TRUE; /* Handle the default selection */
-
- if (CmdDown != 0) /* Handle if the command key was down */
- {
- U_EnableMenus(); /* Let us in to enable and disable menus*/
- mResult = MenuKey(ch); /* See if a menu selection */
- theMenu = HiWord(mResult); /* Get the menu list number */
- theItem = LoWord(mResult); /* Get the menu item number */
- if (theMenu != 0) /* See if a list was selected */
- Handle_My_Menu(theMenu, theItem); /* Do the menu selection */
-
- whichWindow = FrontWindow(); /* Get the front window */
- if ((ch == 'x') || (ch == 'X')) /* Handle a CUT */
- DlgCut(whichWindow);
- if ((ch == 'c') || (ch == 'C')) /* Handle a COPY */
- DlgCopy(whichWindow);
- if ((ch == 'v') || (ch == 'V')) /* Handle a PASTE */
- DlgPaste(whichWindow);
-
- DoTheModelessEvent = FALSE;/* We handled the command key */
- }
- }
-
- if (DoTheModelessEvent == TRUE) /* Do we handle it? */
- {
- if ((DialogSelect(&myEvent, &whichWindow, &itemHit)) || (myEvent.what == mouseDown) || (myEvent.what == keyDown)) /* Ck if do it */
- {
- $$Loop ModelessDialogs
- Do_$Worksheet.name$(&myEvent,whichWindow,itemHit); /* Handle the Modeless Dialog, $Worksheet.FullName$ */
- $$EndLoop
- }
- }
- }
- }
- else
- {
-
- switch (myEvent.what) /* Decide type of event */
- {
- case mouseDown : /* Mouse button pressed */
- code = FindWindow(myEvent.where, &whichWindow);/* Get which window the event happened in */
-
- switch (code) /* Decide type of event again */
- {
- case inMenuBar : /* In the menubar */
- U_EnableMenus(); /* Let us in to enable and disable menus*/
- mResult = MenuSelect(myEvent.where);/* Do menu selection */
- theMenu = HiWord(mResult); /* Get the menu list number */
- theItem = LoWord(mResult); /* Get the menu list item number */
- Handle_My_Menu( theMenu, theItem); /* Handle the menu */
- break;
-
- case inDrag : /* In window drag area */
- DoDrag(whichWindow);/* Go drag the window */
- break;
-
- $$if HasResizableWindows
- case inGrow : /* In window grow area */
- DoGrow(whichWindow);/* Handle the growing */
- break;
-
- $$endif
- $$if HasZoomWindow
- case inZoomIn : /* In window zoom area */
- case inZoomOut : /* In window zoom area */
- DoZoom(whichWindow,code);/* Go zoom the window */
- break;
-
- $$endif
- $$if HasGoAwayBoxes
- case inGoAway : /* In window goaway area */
- DoGoAway(whichWindow);/* Handle the goaway button */
- break;
-
- $$endif
- case inContent : /* In window contents */
- DoInContent(whichWindow,&myEvent);/* Handle the hit inside a window */
- break;
-
- case inSysWindow : /* See if a DA selection */
- SystemClick(&myEvent, whichWindow);/* Let other programs in */
- break;
-
- default: /* Handle others */
- break; /* End of otherwise */
- } /* End of code case */
- break; /* End of MouseDown */
-
- case keyDown: /* Handle key inputs */
- case autoKey: /* and auto repeats */
- DoKeyEvent(); /* Get the key and handle it */
- break;
-
- case updateEvt : /* Update event for a window */
- DoUpdate(); /* Handle the update */
- break;
-
- case diskEvt : /* Disk inserted event */
- DoDiskEvent(); /* Handle a disk event */
- break;
-
- case activateEvt : /* Window activated event */
- DoActivate(); /* Handle the activation */
- break;
-
- case osEvt: /* OS event */
- DoOSEvent(&myEvent); /* Handle the activation */
- break;
-
- case kHighLevelEvent: /* High Level event */
- if (Has.AppleEvents) /* See if init for Apple Events */
- DoHighLevelEvent(); /* Do AppleEvents */
- break;
-
- default: /* Used for debugging, to see what other events are coming in */
- break; /* End of otherwise */
-
- } /* End of case */
-
- }
- }
- else
- {
- whichWindow = FrontWindow(); /* Get the current front window */
- if (whichWindow != NIL) /* See if we have a window */
- {
- thePeeked = (WindowPeek)whichWindow; /* Peek inside, look for dialog */
- if (thePeeked->windowKind == dialogKind) /* DialogSelect will crash if no dialogs */
- {
- if (DialogSelect(&myEvent, &whichWindow, &itemHit))/* Blink cursor in modeless TEs */
- {
- }
- }
- }
- }
- } /* end of while */
- while (!doneFlag); /* End of the event loop */
-
- ApplExit$Prototype.name$(); /* Handle extra program termination code */
-
- $$Loop ModelessDialogs
- Close_$Worksheet.name$(Rec_$Worksheet.name$.theDialog);/* Close this modeless dialog */
- $$EndLoop
- $$Loop Windows
- Close_$Worksheet.name$((WindowPtr)-1); /* Close this window */
- $$EndLoop
-
- SetPreferences(); /* Set new preferences */
-
- } /* end of main */
- $$CloseFile
-
-